package cn.kgc.controller;

import cn.kgc.entity.City;
import cn.kgc.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author mosin
 * date 2022/1/12
 * @version 1.0
 */
@RestController
public class CityController {
    @Autowired
    private CityService cityService;

    //查询
    @GetMapping("/cities")
    public List<City> getAll(){
        return   cityService.getAll();
    }

    //添加
    @PostMapping("/cities")
    public City addCity(@RequestBody City city){
        City city1 = cityService.addCity(city);
        return  city1;
    }

    //根据id 查询城市信息
    @GetMapping("/cities/{id}")
    public City city(@PathVariable Integer id){
        City city = cityService.getOne(id);
        return  city;
    }

}
